/*
 * CatalogueRemoteFactory.java
 *
 * Created on April 23, 2007, 12:22 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package usyd.comp5348;

import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import usyd.comp5348.utils.*;

/**
 *
 * @author david
 */
public class CatalogueRemoteFactory {
    
 private static final String NAME = "ejb/Catalogue";
    
    private static String getBeanName() {
        return NAME;
    }
    
    CatalogueRemote cr = null;
    
    private static CatalogueRemoteFactory instance = null;
    
    private InitialContext context = null;
    
    /**
     * Creates a new instance of StockRemoteFactory
     */
    private CatalogueRemoteFactory() throws NamingException {
        context = new InitialContext();
    }
    
    public static CatalogueRemoteFactory getInstance() throws NamingException {
        if (instance==null)
            instance = new CatalogueRemoteFactory();
        return instance;
    }
    
    /*
     *There is only 1 instance in the system - almost a singleton in a singleton
     */
    public CatalogueRemote getCatalogueRemote() throws NamingException {
        if (cr==null) {
            context.addToEnvironment("org.omg.CORBA.ORBInitialHost",(SettingsProvider.getCentralOfficeAddress()));
            context.addToEnvironment("org.omg.CORBA.ORBInitialPort","3700");
            context.addToEnvironment("java.naming.provider.url", "iiop://" + SettingsProvider.getCentralOfficeAddress() +":3700");
            cr = (CatalogueRemote)context.lookup(getBeanName());
        }
        return cr;
    }
    
}
